package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.BaseObjectBean;
import cn.xfdzx.android.apps.shop.bean.LoginBean;
import cn.xfdzx.android.apps.shop.bean.NewOrderBeen;
import cn.xfdzx.android.apps.shop.contract.PayContract;
import cn.xfdzx.android.apps.shop.model.PayModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class OrderPayPresenter extends BasePresenter<PayContract.View> implements PayContract.Presenter {

    private PayContract.Model model;

    public OrderPayPresenter() {
        model = new PayModel();
    }


    @Override
    public void confirmOrder(String orderKey, String couponId, String marks, String payType, String pinkId, String seckill_id, String addressId, String useIntegral, String leftName, String rightName,String delivery_method,String logistics_type,String  order_express_type) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.confirmOrder( orderKey,  couponId,  marks,  payType,  pinkId,  seckill_id,  addressId,  useIntegral,  leftName,  rightName,delivery_method,logistics_type,  order_express_type) .compose(RxScheduler.<NewOrderBeen>Flo_io_main())
                .as(mView.<NewOrderBeen>bindAutoDispose())
                .subscribe(new Consumer<NewOrderBeen>() {
                    @Override
                    public void accept(NewOrderBeen bean) throws Exception {
                        mView.onConfirmOrderSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
    @Override
    public void toPay(String from, String paytype, String uni ) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.toPay(from, paytype,uni)
                .compose(RxScheduler.<NewOrderBeen>Flo_io_main())
                .as(mView.<NewOrderBeen>bindAutoDispose())
                .subscribe(new Consumer<NewOrderBeen>() {
                    @Override
                    public void accept(NewOrderBeen bean) throws Exception {
                        mView.onPaySuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
